﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Omnia.ViewModels;

namespace Omnia.Wallet.Views
{
    public partial class TransactionEditView : PhoneApplicationPage
    {
        TransactionEditViewModel viewmodel;

        public TransactionEditView()
        {
            InitializeComponent();
            viewmodel = (TransactionEditViewModel)LayoutRoot.DataContext;
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (e.NavigationMode != NavigationMode.Back)
            {
                Uri backUri = NavigationService.BackStack.FirstOrDefault().Source;
                this.NavigationService.RemoveBackEntry();
                base.OnNavigatedTo(e);
                string guid = NavigationContext.QueryString["Guid"].ToString();
                viewmodel.Guid = guid;
                Tag = backUri;
            }
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            base.OnBackKeyPress(e);
            NavigationService.Navigate(new Uri("/Views/TransactionsView.xaml", UriKind.RelativeOrAbsolute));
        }

        private void ListPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            viewmodel.RefreshCategory();
        }
    }
}